package com.owen.system.keep.consumption.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.owen.common.utils.ShiroUtils;
import com.owen.common.utils.SnowflakeIdWorker;
import com.owen.system.keep.consumption.dao.KeepConsumptionTypeDao;
import com.owen.system.keep.consumption.dto.KeepConsumptionTypeDTO;
import com.owen.system.keep.consumption.entity.KeepConsumptionType;
import com.owen.system.keep.consumption.service.KeepConsumptionTypeService;
import com.owen.system.keep.consumption.vo.KeepConsumptionTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 消费类型服务实现
 */
@Service
public class KeepConsumptionTypeServiceImpl implements KeepConsumptionTypeService {

    @Autowired
    private KeepConsumptionTypeDao keepConsumptionTypeDao;

    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;

    @Override
    public KeepConsumptionTypeVO get(String id) {
        return keepConsumptionTypeDao.get(id);
    }

    @Override
    public List<KeepConsumptionTypeVO> list(Map<String, Object> map) {
        return keepConsumptionTypeDao.list(map);
    }

    @Override
    public List<KeepConsumptionTypeVO> selectByKeepAccountIdAndConsumptionType(String keepAccountId, String consumptionType) {
        return keepConsumptionTypeDao.findByKeepAccountIdAndConsumptionType(keepAccountId, consumptionType);
    }

    @Override
    public int count(Map<String, Object> map) {
        return keepConsumptionTypeDao.count(map);
    }

    @Override
    public int save(KeepConsumptionTypeDTO keepConsumptionTypeDTO) {
        String userId = ShiroUtils.getUserId();
        Assert.isTrue(ObjectUtil.isNotEmpty(userId), "请登录");
        KeepConsumptionType keepConsumptionType = BeanUtil.toBean(keepConsumptionTypeDTO, KeepConsumptionType.class);
        keepConsumptionType.setId(snowflakeIdWorker.nextIdStr());
        keepConsumptionType.setCreateTime(new Date());
        keepConsumptionType.setCreateBy(userId);
        return keepConsumptionTypeDao.save(keepConsumptionType);
    }

    @Override
    public int update(KeepConsumptionTypeDTO keepConsumptionTypeDTO) {
        String userId = ShiroUtils.getUserId();
        Assert.isTrue(ObjectUtil.isNotEmpty(userId), "请登录");
        KeepConsumptionType keepConsumptionType = BeanUtil.toBean(keepConsumptionTypeDTO, KeepConsumptionType.class);
        return keepConsumptionTypeDao.update(keepConsumptionType);
    }

    @Override
    public int remove(String id) {
        return keepConsumptionTypeDao.remove(id);
    }

    @Override
    public int batchRemove(String[] ids) {
        return keepConsumptionTypeDao.batchRemove(ids);
    }

}
